 package ControlLayer;
import ModelLayer.*;

import java.util.ArrayList;


/**
 * This is a controller class for handling loans.
 * 
 * @author Sebastian K Munch
 * @version 08-11-2012
 */
public class LoanCtr
{
    private static LoanContainer loans;
    private long loanIDCount = 0;
    /**
     * Constructor for objects of class LoanCtr
     */
    public LoanCtr()
    {
        loans = LoanContainer.getInstance();
    }
    
    /**
     * This method creates a new Loan and associates it with the container.
     * 
     * @param   dvdID           The id of the dvd that is being loaned. A long.
     * @param   serialNumber    The serial number of the copy that is being loaned. A String.
     * @param   personID        The id of the person making the loan. 
     */
    public void createLoan(DVD dvd, Copy copy, Person person, String loanMade, String toBeReturned)
    {
        loanIDCount++;
        Loan l = new Loan(dvd,copy,person,loanIDCount,loanMade,toBeReturned);
        loans.addLoan(l);
    }
    
    /**
     * This method returns a Loan identified by id. If none is found null is returned
     * 
     * @param   id  The id of the Loan to be returned. A Long.
     */
    public Loan findLoan(long id)
    {
        return loans.findLoan(id);
    }
    
    /**
     * The method removes a loan identified by the give id.
     * 
     * @param   id  The id of the loan to be removed. A long.
     */
    public boolean removeLoan(long id)
    {
        return loans.removeLoan(id);
    }
    
    /**
     * This method returns a list of loans.
     * 
     * @return  A list of loans, an an ArrayList<Loan>
     */
    public ArrayList<Loan> listAllLoans()
    {
        return loans.listAllLoans();
    }
}
